package com.example.demo.mapper;

import com.example.demo.entity.Sign;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface SignMapper {
    @Select("select * from sign where username=#{username} and name=#{name}")
    Sign selectByName(@Param("name") String name,@Param("username") String username);//查找标签是否存在

    @Select("select * from sign where name=#{name} and username=#{username} and path=#{path}")
    Sign selectSign(@Param("name") String name,@Param("username") String username,@Param("path") String path);//查找文件某标签是否存在



    @Select("select * from sign where name=#{name} and username=#{username} and path=#{path}")
    Sign selectSign2(Sign sign);//同上

    @Select("select name from sign where username=#{username} and path=#{path}")
    List<String> selectSignAll(Sign sign);//获取某路径文件的所有标签

    @Select("select name,COUNT(*)AS'signNum' from sign where username=#{username} GROUP BY name")
    List<Map> selectAllSign(String username);//获取该用户下所有标签及其数量

    @Insert("insert into sign(name,username) value (#{name}, #{username})")
    Integer insertSign(Sign sign);//新建标签

    @Insert("insert into sign(name,username,path) value (#{name}, #{username}, #{path})")
    Integer insertSignFile(Sign sign);//新建文件标签

    @Delete("delete from sign where path=#{path} and name=#{name} and username=#{username}")
    Integer deleteSignFile(Sign sign);//删除文件标签

    @Delete("delete from sign where path=#{path} and username=#{username}")
    Integer deleteSignFile2(String path,String username);//删除文件标签
}
